# -*- coding: utf-8 -*-
# @Author : HaleShi
# @Time : 2023-06-25
# @File : 13_hook_doFinal.py

import frida
import sys

str_host = "127.0.0.1:8877"
manager = frida.get_device_manager()
rdev = manager.add_remote_device(str_host)
pid = rdev.attach("唯品会")
session = rdev.attach(pid)

scr = """
Java.perform(function () {
    var Cipher = Java.use("javax.crypto.Cipher");
    var ByteString = Java.use("com.android.okhttp.okio.ByteString");

    Cipher.doFinal.overload('[B').implementation = function (data) {
        console.log("-----------------------AES加密---------------------------");
        console.log("AES明文：",ByteString.of(data).utf8());
        var res = this.doFinal(data);
        // console.log('AES密文：',JSON.stringify(res));
        console.log('AES密文：',ByteString.of(res).hex());
        console.log(Java.use("android.util.Log").getStackTraceString(Java.use("java.lang.Throwable").$new()));
        return res;
    }

});
"""
script = session.create_script(scr)


def on_message(message, data):
    print(message, data)


script.on("message", on_message)

script.load()
rdev.resume(pid)
sys.stdin.read()
